import { watch, onMounted } from 'vue'

export function watchFocus(focusChart, charts) {
  watch(focusChart, (now, prev) => {
    const chart = now ? now : prev;

    // 图表尺寸自适应
    for (let i = 0; i < 3; i++) {
      setTimeout(() => {
        charts[now ? now : prev].resize();
      }, i * 500);
    }
  });
}

export function watchResize(charts) {
  window.addEventListener('resize', function () {
    Object.keys(charts).forEach((e) => {
      charts[e].resize();
    });
  });
}